* tables: includes output tables
* figures: includes output figures

********************************************************************************

* Define the main directory
*global main="H:\.shortcut-targets-by-id\1kY_7b-sgXU8OC8NuKkyBOx1UdqZCLjMM\primary-adoption-2021"
global main="****YOUR DIRECTORY HERE*****"

* Define data directory
global data="****YOUR DIRECTORY HERE*****"

* Define figures directory
global figures="****YOUR DIRECTORY HERE*****"

********************************************************************************
*Import and Prep Data*
********************************************************************************

cd "$data"

use FinalData.dta, clear

*Core Models*
logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)
logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="North", cluster (stateid)
logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="South", cluster (stateid)
logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="West", cluster (stateid)


*Figures*
	
	**Progressive Movement**
	preserve
	logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)
	margins, at (log_rob_prog_3=(0 2.3025851 2.9957323 3.4011974 3.6888795 3.912023 4.0943446 4.2484952 4.3820266 4.4998097 4.6051702)) saving("tmp", replace) 
	use "tmp", clear
	gen value=_at*10-10
	tw (line _margin value, lcolor(black) leg(off) ytitle("Probability of Adoption of Primary") xtitle("Strength of Progressive Movement") ymtick(##5, nogrid) xlabel(,nogrid) ylabel(,nogrid)) (line _ci_lb value, lpattern(dash) lcolor(gs8))(line _ci_ub value, lpattern(dash) lcolor(gs8))
	cd "$figures"
	graph save ProgressiveStrength, replace
	restore

	**Urbanization**
	logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)
	margins, at (deltaurban=(-2(.05)1.5))
	marginsplot, xscale(range(-2 1.5)) xlabel(-2(.5)1.5, nogrid) ylabel(,nogrid) ymtick(##5, nogrid) recastci(rline) ciopts(lpattern(dash)) recast(line) ytitle("Probability of Adoption of Primary") xtitle ("Change in Urban Population") title("") 
	cd "$figures"
	graph save UrbanGrowth, replace
	
	
	***Robustness Checks***
***********************

*Populism Variations** -- TABLE 1A
	*92 Populist Vote*
	logit primary_adoption_strict deltaurban one_party_sw_3 logpopulist92 imp_income borderadoptedprev year, cluster (stateid)
	*Non-Logged*
	logit primary_adoption_strict deltaurban one_party_sw_3 populist92 imp_income borderadoptedprev year, cluster (stateid)
	*State Leg Populist Max*
	logit primary_adoption_strict deltaurban one_party_sw_3 p_house_pct_max imp_income borderadoptedprev year, cluster (stateid)
	
	
	*Urban Change Variations* -- TABLE 5A
	*Population Change instead of Urban*
	logit primary_adoption_strict pop_change_2 one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)
	logit primary_adoption_strict imp_pop one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)

*Party Control Variations*  -- TABLE 4A
	logit primary_adoption_strict deltaurban control_loss_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)

*Interacting Urban with Progressivism -- TABLE 2A 
	logit primary_adoption_strict c.deltaurban##c.log_rob_prog_3  one_party_sw_3 imp_income borderadoptedprev year, cluster (stateid)
	logit primary_adoption_strict c.deltaurban##c.log_rob_prog_3  one_party_sw_3 imp_income borderadoptedprev year if region_4_cat =="North", cluster (stateid)
	
	
	Interacting Progressivism with One-Party* -- Souraf TABLE 3A
	logit primary_adoption_strict i.one_party_sw_3##c.log_rob_prog_3  c.deltaurban imp_income borderadoptedprev year, cluster (stateid)
	logit primary_adoption_strict i.one_party_sw_3##c.log_rob_prog_3  c.deltaurban imp_income borderadoptedprev year if region_4_cat =="North", cluster (stateid)
	
	*Not included*
	logit primary_adoption_strict i.one_party_sw_3##c.logp_house_pct_max c.deltaurban imp_income borderadoptedprev year, cluster (stateid)
	logit primary_adoption_strict i.one_party_sw_3##c.logp_house_pct_max c.deltaurban imp_income borderadoptedprev year if region_4_cat =="North", cluster (stateid)
	
	
	logit primary_adoption_strict i.one_party_sw_3##c.logpopulist92  c.deltaurban imp_income borderadoptedprev year, cluster (stateid)

	
*CLogLog Versions* -- TABLE 6A
	cloglog primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year, cluster (stateid)
	cloglog primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="North", cluster (stateid)
	cloglog primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="South", cluster (stateid)
	cloglog primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if region_4_cat =="West", cluster (stateid)

*Pre-1910 Only*
	logit primary_adoption_strict deltaurban one_party_sw_3 log_rob_prog_3 imp_income borderadoptedprev year if year<1911, cluster (stateid)
